layui.use(['table', 'form', 'layer' ], function() {
  var table = layui.table;
  var layer = layui.layer;
  table.render({
    elem: '#info-table'
    ,title: '信息展示'
    ,url: ctx + './sys/info/list' +
        ''
    ,parseData: function(res){ //res 即为原始返回的数据
      return {
        "code": res.code, //解析接口状态
        "msg": res.msg, //解析提示文本
        "count": res.page.totalCount, //解析数据长度
        "data": res.page.list //解析数据列表
      };
    }
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field:'id', title:'ID',  fixed: 'left',  sort: true, width: 100}
      ,{field:'userId', title:'负责人ID' , width: 100}
      ,{field:'dutyUserName', title:'责任领导' ,width:100}
      ,{field:'orgName', title:'企业名称' ,width:250}
      ,{field:'orgAdd', title:'企业地址' ,width:100}
      ,{field:'business', title:'主要业务活动' ,width:100}
      ,{field:'special', title:'专业' ,width:100}
      ,{field:'legal', title:'法人姓名' ,width:100}
      ,{field:'status', title:'经营状态' ,width:100}
      ,{field:'regCapital', title:'注册资本' ,width:100}
      ,{field:'contact', title:'企业联系人' ,width:100}
      ,{field:'contactJob', title:'联系人职务' ,width:100}
      ,{field:'contactPhone', title:'联系电话' ,width:100}
      ,{field:'dept', title:'分包单位' ,width:100}
      ,{field:'leader', title:'市级分包领导' ,width:100}
      ,{field:'leaderJob', title:'分包领导职务' ,width:100}
      ,{field:'leaderPhone', title:'联系电话' ,width:100}
      ,{field:'leaderContact', title:'联络人' ,width:100}
      ,{field:'leaderContactJob', title:'联络人职务' ,width:100}
      ,{field:'leaderContactPhone', title:'联络人联系电话' ,width:100}
      ,{field:'createTime', title:'创建时间' ,width:100}
      ,{fixed: 'right', title: '操作', toolbar: '#toolbar', width: 200}
    ]]
    ,page: true
  });
  table.on('tool(info-table)', function (obj) {
    switch (obj.event) {
      case 'edit':
        layer.open({
          title: false,
          type: 2,
          area: ['650px', '610px'],
          content: ctx + 'sys/info-edit.html?id=' + obj.data.id,
          end: function () {
            location.reload();
          }
        })
        break;
        break;
      case 'del':
        layer.open({
          content: '确定要删除'
          ,btn: ['删除', '取消']
          ,yes: function(index, layero){
            axios.post(ctx + 'sys/info/delete', [obj.data.id]).then(function (res) {
              if (res.data.code == 0) {
                layer.msg('删除成功');
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                location.reload();
              } else {
                parent.layer.msg(res.data.msg);
              }

            })
          }
          ,btn2: function(index, layero){

          }
          ,cancel: function(){
            //右上角关闭回调
          }
        });
        break;
    }
  });


  $('#add-btn').click(function () {
    layer.open({
      title: false,
      type: 2,
      area: ['680px', '360px'],
      content: ctx + 'sys/info-add.html',
      end: function () {
        location.reload();
      }
    })
  })



});





